package main

import (
	__ "ai_srv/basic/ai_proto"
	"context"
	"fmt"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"log"
	"time"
)

func main() {
	// 等待服务启动
	fmt.Println("等待AI服务启动...")
	time.Sleep(3 * time.Second)
	
	// 连接到gRPC服务器
	conn, err := grpc.Dial("127.0.0.1:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("连接失败: %v", err)
	}
	defer conn.Close()

	// 创建AI服务客户端
	client := __.NewAiClient(conn)
	ctx := context.Background()

	// 测试用户ID
	userID := int32(1)

	fmt.Println("=== 天气功能测试 ===")

	// 测试天气查询
	req := &__.ChatWithAIReq{
		UserId:    userID,
		SessionId: "", // 创建新会话
		Message:   "上海今天天气怎么样？",
	}

	resp, err := client.ChatWithAI(ctx, req)
	if err != nil {
		log.Fatalf("天气查询失败: %v", err)
	}

	fmt.Printf("用户: %s\n", req.Message)
	fmt.Printf("AI回复:\n%s\n", resp.ChatWithAI)
	fmt.Printf("会话ID: %s\n", resp.SessionId)
	
	fmt.Println("\n=== 测试完成 ===")
}